﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Pages/Site.Master" AutoEventWireup="true"
    CodeBehind="Individual.aspx.cs" Inherits="_1041345_1041368_1041422_DoAnCuoiKy.Pages.Individual" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <%--Thư viện sử dụng Ajax--%>
    <script src="../Scripts/Lib/jquery_1.7.1.js" type="text/javascript"></script>
    <%--Thư viện sử dụng jQuery--%>
    <script src="../Scripts/Lib/jquery.alerts.js" type="text/javascript"></script>
    <script src="../Scripts/Lib/jquery.ui.draggable.js" type="text/javascript"></script>
    <script src="../Scripts/Lib/jquery.ui.dialog.js" type="text/javascript"></script>   
    <script src="../Scripts/Lib/jquery.simplemodal.js" type="text/javascript"></script>
    <%--Thư viện CSS cho jQuery--%>
    <link href="../Styles/jquery.alerts.css" rel="stylesheet" type="text/css" /> 
    <script type="text/javascript">
        function LoadLink() 
        {
            $(".selected").html("");
            var str = "<tr><td align='center' width='15%' bgcolor='pink'><b>Number</b></td><td align='center' width='70%' bgcolor='pink'><b>Selected</b></td><td align='center' width='15%' bgcolor='pink'><b>Delete</b></td></tr>";
            $(".selected").append(str);
            var a = window.location.href.toString().split('?');
            var b = a[1].split('=');
            $.ajax(
            {
                type: "GET",
                url: "http://localhost:9999/Service1.svc/GetLink/" + b[1].toString(),
                dataType: "xml",
                success: function (xml) 
                {
                    var i = 1;
                    $(xml).find("FeedPersonal_DTO").each(function () 
                    {
                        str = "<tr><td align='center' width='15%'>" + i + "</td><td align='left' width='70%'><u><a href=" + $(this).find("Link").text() + ">" + $(this).find("Link").text() + "</a></u></td><td align='center' width='15%'><b><a href='../Pages/Handle.aspx?Handle=Delete&ID=" + b[1].toString() + "&STT=" + $(this).find("MaFeedPersonal").text() + "' onclick=''>X</a></b></td></tr>";
                        i += 1;
                        $(".selected").append(str);
                    });
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert("Error Load Feed !!!" + textStatus + jqXHR + errorThrown);
                }
            });
        }
                
        function AddLink() 
        {
            if ($("#txtLink").val() == "")
                jAlert("Invalid Link !!!", 'Alert');
            else 
            {
                var a = window.location.href.toString().split('?');
                var b = a[1].split('=');
                var link = document.getElementById("txtLink").value;
                var request = new XMLHttpRequest();
                var data = "<Feed><IDAccess>" + b[1].toString() + "</IDAccess>" + "<Link>" + link + "</Link></Feed>";
                var url = "http://localhost:9999/Service1.svc/Insert/";
                request.open("POST", url, true);
                request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                request.onreadeystatechange = function () 
                {
                    if (request.readyState == 4) {
                        if (request.status == 200) {
                            var response = request.responseText;
                            jAlert(response);
                        }
                    }
                }
                request.send(data);
                $("#txtLink").val("");
                jAlert(" Successful !!!", 'Information');                
                LoadLink();                            
            }
        }

        function ViewFeed() 
        {
            $(".detail").html("");
            var a = window.location.href.toString().split('?');
            var b = a[1].split('=');
            var str = "<tr><td align='center' width='30%' bgcolor='pink'><b>Title</b></td><td align='center' width='70%' bgcolor='pink'><b>Description</b></td></tr>";
            $(".detail").append(str);
            $.ajax(
            {
                type: "GET",
                url: "http://localhost:9999/Service1.svc/GetFeedByID/" + b[1].toString(),
                dataType: "xml",
                success: function (xml) 
                {
                    $(xml).find("DataFeed_DTO").each(function () 
                    {
                        str = "<tr><td align='center' width='30%'><u><a href=" + $(this).find("Link").text() + ">" + $(this).find("Title").text() + "</a></u></td><td align='left' width='70%'>" + $(this).find("Description").text() + "</td><tr>";
                        $(".detail").append(str);
                    });
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    jAlert(" Error load feed !!!", 'Alert');
                }
            });
        }

    </script>
    <table style="width: 100%;" border='0' cellspacing='0' cellpadding='0'>
        <tr>
            <td align="center">
                Link :
            </td>
            <td align="left">
                <input id="txtLink" type="text" placeholder="Paste link here" />
                <input id="btnAdd" type="button" value="Add" onclick="AddLink()"/>                
            </td>
        </tr>
    </table>
    <br/>
    <table style="width: 100%;" border='1' cellspacing='0' cellpadding='0' class='selected'>        
    </table>    
    <br/>
    <table style="width: 100%;" border='0' cellspacing='0' cellpadding='0'>
        <tr>
            <td align="center">  
                <input id="btnView" type="button" value="View" onclick="ViewFeed()"/>               
            </td>                                        
        </tr>
    </table>
    <br/>       
    <table style="width: 100%;" class='detail' border='1' cellspacing='0' cellpadding='0'>                    
    </table>
    <script type="text/javascript">
        LoadLink(); 
    </script>
</asp:Content>
